//牛客KY9 成绩排序
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct Stu 
{
    int no;
    int s;
};
bool cmp1(struct Stu x,struct Stu y)
{
    return x.s<y.s;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        struct Stu arr[100];
        for(int i =0;i<n;++i)
        {
            int x;
            scanf("%d",&x);
            arr[x].no=x;
            scanf("%d",&arr[x].s);
        }
        stable_sort(arr,arr+n,cmp1);
        for(int k=0;k<n;++k)
        {
            printf("%d %d\n",arr[k].no,arr[k].s);
        }
    }
    return 0;
}